#include "Worker.h"

Worker* Worker::Read(ifstream &file)
{
	char line[256];
	m_name->Read(file);

	if (file.is_open() || !file.eof())
	{
		file >> m_years;
	}

	if (file.is_open() || !file.eof())
	{
		file >> m_rank;
		file.getline(line,256);
		return this;
	}
	
	return NULL;

	//creates an object of worker from the worker data in the file
	//returns the new worker object or null if there is an error
}

Worker* Worker::Read()
{
	char junk[256];
	m_name->Read();

	cout << "Please enter the years and the rank of the worker: " ;
	try
	{
		cin >> m_years;
		cin >> m_rank;
	}
	catch (char *str)
	{
		cout << "an exception raised: non int has been entered!" << endl;
		return NULL;
	}
	cin.getline(junk,255);
	return this;

	//creates an object of worker from the worker data from the keyboard
	//returns the new worker object or null if there is an error
}

void Worker::Print()
{
	if (m_name)
	{
		m_name->Print();
		cout << "\t" << m_years << "\t" << m_rank << endl;
	}
}

Worker::~Worker(void)
{
}
